package EMS::Mailguard::Mailguardout;

use Data::Dumper;
use Mail::Sendmail;

my $VERSION  = '0.01';
my %DEFAULTS = ();

sub new {
    my $self = {};
    my $class = shift();
    my %DEFAULTS = (
		    @_
		    );

    for ( sort ( keys %DEFAULTS ) ){
	  $self->{$_} = $DEFAULTS{$_}
    }
    our $log = $DEFAULTS{logobject};
    bless($self, $class);
    return $self;
}


sub SendMessage{
    $self=shift;
    my %args=(
	    recipients => undef,
	    additional_headers => undef, 
        body_text_blurb => undef, 
        sendmail_params => undef,
        message_params => undef,
	    @_
    );   


    # Set up the mail headers
     my %mail = (
 		To      		=> join(',',@$args{recipients}),
 		From    		=> 'mailguard@demodomain.com',
 		Subject 		=> "Subject left blank",
 		'X-Mailer' 		=> "Mailguard 2.0",
 		'X-Mailguard-pid'	=> $$,
        %{+ $args{message_params} }
	);



   # Prepend the blurb
   $mail{Message} = $args{body_text_blurb} . $mail{Message};

   for ( keys ( %mail ) ){
     undef $mail{$_} unless (/\w+/);
     chomp $mail{$_};
   }

   for (keys(%sm)){
     $sm{$_}=~m,(.*),;
     $sm{$_}=$1;
     $log->add("The sendmail conf hash is $_ : $sm{$_}");
   }

   sendmail(%mail) or $Mail::Sendmail::error;
   $log->add("Sender Notification Ended Successfully");
   $log->add($Mail::Sendmail::log);

    return;
}# end SendMessage()


sub dumpToAHandle{
    my %def=(
	      content=>"foo",
	      handle=>'',
  	      @_
	     );
    $h=$def{handle};


  if ( not $def{handle}){
      print STDOUT  $def{content}
  }else{
      print $h  $def{content}
  }

}

###############################################################################
# POD Documentation
###############################################################################
=pod

=head1 EMS::Mailguard::Mailguardout

=head2 Synopsis

A light wrapper around Mail::Sendmail

=head2 Constructor

=over 4

=item * 

recipients : Reference to an array of recipients

=item * 

additional_headers : Not implemented presently

=item * 

body_text_blurb  : Blurb that will be placed above body text

=item * 

sendmail_params  : Not implemented presently

=item * 

message_params : A Hash of values that can be used to override the default
mail setup.

=head2 AUTHOR

Steven G. Harms (stharms@cisco.com)

=cut

return 1;
